﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ArgusLib.Xml;

namespace ArgusLib.Controls
{
	public partial class UpdateInfoBox : BaseForm
	{
		public static void Show(UpdateInfo updateInfo)
		{
			if (updateInfo == null)
				throw new ArgumentNullException("updateInfo");
			UpdateInfoBox box = new UpdateInfoBox(updateInfo);
			box.ShowDialog();
		}

		private UpdateInfoBox(UpdateInfo updateInfo)
		{
			InitializeComponent();
			this.Initialize(updateInfo);
		}

		protected UpdateInfo UpdateInfo{get;private set;}
		protected string DownloadLinkText { get { return this.lDownload.Text; } set { this.lDownload.Text = value; } }

		protected virtual void Initialize(UpdateInfo updateInfo)
		{
			this.UpdateInfo = updateInfo;
			this.lBuildname.Text = updateInfo.BuildName;
			this.lStatus.Text = updateInfo.ReleaseStatus.ToString();
			this.lDownload.Text = updateInfo.DownloadLink;
			StringBuilder sb = new StringBuilder();
			foreach (string line in updateInfo.Description)
				sb.AppendLine(line);
			this.tbDescription.Text = sb.ToString();
		}

		private void lDownload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			this.OnLinkClicked();
		}

		protected virtual void OnLinkClicked()
		{
			System.Diagnostics.Process.Start(this.UpdateInfo.DownloadLink);
		}
	}
}
